package Question3;

import java.util.*;

/**
 * Created by lenovo on 2017/3/6.
 */
public class Main {

    public static List<String> lists = new ArrayList<>();

    private void fullPermutation(Vector<Character> sourse,Vector<Character> result,List<String> lists){
        if(sourse.size()==0){
            String str = "";
            for(int i =0;i<result.size();i++){
                str+=result.elementAt(i);
            }
            lists.add(str);
            return;
        }

        for(int i=0;i<sourse.size();i++){
            Vector<Character> tsource = new Vector<>(sourse);
            Vector<Character> tresult = new Vector<>(result);
            tresult.add(sourse.elementAt(i));
            tsource.remove(i);
            new Question3.Main().fullPermutation(tsource,tresult,lists);
        }
    }

    public static Boolean panDuan(String str){
        Integer x1 = Integer.parseInt(str.substring(0,2));
        Integer x2 = Integer.parseInt(str.substring(2,4));
        Integer y1 = Integer.parseInt(str.substring(4,6));
        Integer y2 = Integer.parseInt(str.substring(6,9));

        return x1*x2 == y1 * y2?Boolean.TRUE:Boolean.FALSE;
    }

    public static Boolean chongFu(String str,List<String> panDuan){
        return panDuan.indexOf(str.substring(2,4)+str.substring(0,2))!=-1?Boolean.TRUE:Boolean.FALSE;
    }
    public  static void main(String[] args){

        Vector<Character> sourse = new Vector<>();
        Vector<Character> result = new Vector<>();
        List<String> panDuan = new ArrayList<>();

        for(int i =1;i<=9;i++){
            sourse.add((char)('0'+i));
        }

        new Question3.Main().fullPermutation(sourse,result,lists);

        for(String str : lists){
            if(Main.panDuan(str)&&(!Main.chongFu(str,panDuan))){
                System.out.println(str.substring(0,2)+"x"+str.substring(2,4)+"="+str.substring(4,6)+"x"+str.substring(6,9));
                panDuan.add(str.substring(0,4));
            }
        }

    }
}
